package cn.springboot.erp.controller;

import cn.springboot.erp.commons.QueryParams;
import cn.springboot.erp.commons.ResponseResult;
import cn.springboot.erp.entity.SalesOrderDetails;
import cn.springboot.erp.service.SalesOrderDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(tags = "单据管理")
@RequestMapping("salesOrdersDetails")
public class SalesOrdersDetailsController {


    @Resource
    public SalesOrderDetailsService salesOrderDetailsService;

    @ApiOperation("数据分页")
    @PostMapping("page")
    public ResponseResult listPage(@RequestBody QueryParams<SalesOrderDetails> queryParams){
        return salesOrderDetailsService.listPage(queryParams);
    }

    @ApiOperation("根据id删除")
    @GetMapping("deleteById/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id){
        salesOrderDetailsService.removeById(id);
        return ResponseResult.Success().msg("删除成功");
    }

    @ApiOperation("添加单据")
    @PostMapping("insert")
    public ResponseResult insert(@RequestBody SalesOrderDetails salesOrderDetails){
        salesOrderDetailsService.save(salesOrderDetails);
        return ResponseResult.Success().msg("添加成功");
    }
}
